#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

void *showThread(void *args)
{
    // pthread_detach(pthread_self());
    (void)args;
    int a = 10;
    cout << "该次线程的id为: " << pthread_self() << "该次线程定义的变量的地址在: " << &a << endl;
    sleep(3);
    pthread_exit(nullptr);
}

int main()
{
    pthread_mutex_t mtx; // 在函数内初始化一把锁
    pthread_mutex_init(&mtx, nullptr);
    cout << &mtx << endl;
    pthread_t t1, t2, t3;
    pthread_create(&t1, nullptr, showThread, (void *)"Thread 1");
    pthread_create(&t2, nullptr, showThread, (void *)"Thread 2");
    pthread_create(&t3, nullptr, showThread, (void *)"Thread 3");
    cout << "主线程等" << endl;
    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    pthread_join(t3, nullptr);

    return 0;
}